package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import androidx.activity.viewModels
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.bean.old.RDProjectDetailBean
import com.hinnotek.amoeba.databinding.ActivityRdProjectDetailBinding
import com.hinnotek.amoeba.dialog.CustomDialog
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.viewmodels.ProjectViewModel
import com.lee.common.network.net.ObserverState

class RDProjectDetailActivity : BaseActivity<ActivityRdProjectDetailBinding>() {

    private var customDialog: CustomDialog? = null

    val viewModel by viewModels<ProjectViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_rd_project_detail)
        setLeftVisible(true)
        val titleUser = intent.getStringExtra("title")
        setTitle(titleUser)

    }

    override fun initVew() {
    }

    override fun setData() {
        val amibaProjectId = intent.getIntExtra("amibaProjectId", -1)
        getAmibaProjectById(amibaProjectId)
    }

    /**
     * 查询阿米巴研发项目详情接口
     * @param amibaProjectId
     */
    fun getAmibaProjectById(amibaProjectId: Int) {
        customDialog = CustomDialog(mContext, "正在加载...")
        customDialog?.show()

        viewModel.getAmibaProjectById(amibaProjectId).observe(this,object : ObserverState<RDProjectDetailBean>(){
            override fun onDataChange(data: RDProjectDetailBean) {
                customDialog?.dismiss()

                bindingView.tvRdCreateProject.text = data.projectName
                bindingView.tvRdLaborCost.text = data.totalPerson
                bindingView.tvRdReimbursementCost.setText(data.totalReimburse)
                bindingView.tvRdPaymentCost.setText(data.totalPay)
                bindingView.tvRdPurchaseCost.setText(data.totalPurchase)
                bindingView.tvRdOtherCost.setText(data.totalOther)
                bindingView.tvRdTotalCost.setText(data.allMoney)
                bindingView.tvRdRemainderCost.setText(data.surplusMoney)

                super.onDataChange(data)
            }

            override fun onError(msg: String?, code: Int) {
                customDialog?.dismiss()
                ToastUtils.showShort(mContext, msg)
                super.onError(msg, code)
            }
        })
    }
}